package com.leyantech.ecp.agenx.common.entity;

import com.leyantech.ecp.agenx.common.service.HelaService;

import com.google.gson.reflect.TypeToken;
import com.google.inject.Inject;
import lombok.Getter;

import java.lang.reflect.Type;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;

/**
 * @author eahau, {@literal <eahau@foxmail.com>}
 * @date 2022-11-23.
 */
@Getter
public enum HelaKey {

  ENABLE_ASSISTANT("ecp_enable_assistant_list", new TypeToken<List<NormalAssistantDto>>() {
  }.getType()),

  ECP_SHOP_VERSION("ecp_shop_version", new TypeToken<List<String>>() {
  }.getType()),

  ECP_SEAT_MANAGER_INFO("ecp_seat_manager_info", SeatManagerInfo.class),

  ECP_STORE_SUBSCRIBE_INFO("ecp_store_subscribe_info", HelaStoreSubscribeDto.class),

  ECP_LXK_PRODUCT_SUBSCRIBE_INFO("ecp_lxk_product_subscribe_info",
      EcpLxkProductSubscribeInfo.class),

  ECP_LXK_ASSISTANT_LIST("ecp_lxk_assistant_list", new TypeToken<List<AssistantSeatVO>>() {
  }.getType()),

  ECP_SALES_INFO("ecp_sales_info", SalesInfo.class),

  ECP_SEND_MARKETING_MSG_ASSISTANT_V2("ecp_send_marketing_msg_assistant_v2",
      new TypeToken<List<AssistantSeatVO>>() {
      }.getType()),

  ECP_STORE_BASIC_INFO("ecp_store_basic_info", StoreBasicInfo.class),

  ;

  HelaKey(String key, Type type) {
    this.key = key;
    this.type = type;
  }

  private final String key;

  private final Type type;

  @Inject
  private static HelaService helaService;

  public <T> Optional<T> get(String storeId) {
    return helaService.get(storeId, this);
  }

  public <T> T getOrElse(String storeId, T def) {
    return helaService.<T>get(storeId, this).orElse(def);
  }

  public <T> T getOrElseGet(String storeId, Supplier<T> def) {
    return helaService.<T>get(storeId, this).orElseGet(def);
  }

}
